package com.senlan.water.common.util;

import cn.dev33.satoken.stp.StpUtil;
import com.senlan.water.common.constant.RedisConstant;
import com.senlan.water.dao.domain.User;
import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class UserInfoUtil {

    @Resource
    private Redisson redisson;

    /**
     * 获取登录用户的信息
     * @return
     */
    public User getUserInfo(){
        long userId = StpUtil.getLoginIdAsLong();
        //redis存储用户信息
        RBucket<User> bucket = redisson.getBucket(RedisConstant.USER_INFO_PREFIX + userId);
        if (bucket.isExists()){
            return bucket.get();
        }
        return new User();
    }
}
